from PIL import Image
import cv2

# 定义图片的大小
IMAGE_SIZE = 200

img = Image.open("./dataset/cat.111.jpg")
# 将图片的最小边压缩或者拉伸至 IMAGE_SIZE

if img.width < img.height:
    w = IMAGE_SIZE
    h = int(IMAGE_SIZE * img.height / img.width)
else:
    h = IMAGE_SIZE
    w = int(IMAGE_SIZE * img.width / img.height)

img = img.resize((w, h))
left = int((w - IMAGE_SIZE) / 2)
uper = int((h - IMAGE_SIZE) / 2)
right = int((w + IMAGE_SIZE) / 2)
lower = int((h + IMAGE_SIZE) / 2)
img = img.crop((left, uper, right, lower))
#灰度图像，白色为255，黑色为0；
'''
灰度处理有多种方法：
'''
img = img.convert("L")
#gamma校正：图像亮度与对比度的调整，gamma>1，新图比原图亮度暗。
img.save("./test_cat.jpg")
img.show()
